 #!/opt/php/bin/php -d display_errors=1
<?php 
require_once('TVB/Message/MessageHelper.php');
require_once 'TVB/Message/BaseConsumer.php';
require_once('TVB/pms/pdes/common/bootstrap.php');
require_once('TVB/pms/pdes/common/util/portal/PortalException.class.php');
require_once('TVB/pms/pdes/common/util/portal/PortalData.class.php');

class runPortal extends BaseConsumer{
	private $programme_id;
	protected function process(Stomp_Frame $message){
		$start_time = microtime(TRUE);
			echo date('Y-m-d H:i:s'). ": Start import data....\n";
			$data = $message->map;
			//var_dump($data);
			foreach($data as $objectList){
				if($objectList->object == 'Programme'){
					$task->id = $objectList->id;
					$this->programme_id = $task->id;
					$task->type = $objectList->object;
					$ret = $this->runJob($task);
				}
				if($objectList->object == 'Episode'){
					$task->id = $this->programme_id;
					$task->episode_id = $objectList->id;
					$task->type = $objectList->object;
					$ret = $this->runJob($task);
				}
			}
		return TRUE;
	}
		
    public function runJob($task){
        $dataArray = $this->getPortalData($task);
        $dataArray['action'] = 'publish'; 
		var_dump($dataArray);
        $this->sendToPortal($dataArray);
	}
	public function sendToPortal($dataArray){
    	return PortalData::sendDataToPortal($dataArray);
    }
	public function getPortalData($task) {
    	switch ($task->type) {
        	case 'Programme': $dataArray = PortalData::getPortalData('p_programme', $task->id); break;
    		case 'Episode': $dataArray = PortalData::getPortalData('p_episode', $task->episode_id);break;
    	}               
    	return $dataArray;
    }
}

$cons = new runPortal(AC::CONFIG_MQ, 'PMS_DataComplate');
$cons->run();
?>
